#include <bits/stdc++.h>
// 2025/02/01
// tag: 
// Author: Zhang Muen
using namespace std;

int t, n, m, pos[100005], dis[100005]; 
struct edge{
    int to, w;
    edge(int t = 0, int wo = 0)
        : to(t)
        , w(wo) { };
};
vector<edge> g[100005];
queue<int> q;
bool vis[100005];

signed main()
{
    // Disable synchronization between C++ and C I/O streams
    ios::sync_with_stdio(0);
    // Unbind cin from cout
    cin.tie(0);
    // Read the number of test cases
    cin >> t;
    while (t--){
        // Read the number of nodes and edges
        cin >> n >> m;
        for (int i = 0; i <= n; ++i) {
            g[i].clear();
        }
        // Read the positions of the nodes
        for (int i = 1; i <= n; i++)
            cin >> pos[i]; 
        // Sort the positions of the nodes
        sort(pos + 1, pos + n + 1);
        // Read the edges and add them to the graph
        for (int i = 1; i <= m; i++){
            int u, v, w;
            cin >> u >> v >> w;
            // Find the index of the node in the sorted array
            u = lower_bound(pos + 1, pos + n + 1, u) - pos;
            v = upper_bound(pos + 1, pos + n + 1, v) - pos - 1;
            // Add the edge to the graph
            g[u - 1].emplace_back(v, w);
        }
        // Add edges between adjacent nodes
        for (int i = 0; i <= n; i++){
            if (i != 0)
                g[i - 1].emplace_back(i, 0), dis[i] = -1e9;
            if (i != n)
                g[i].emplace_back(i - 1, -1);
        }
        // Initialize the queue and add the source node
        q.push(0);
        // Perform a breadth-first search
        while (!q.empty()){
            int u = q.front();
            q.pop();
            vis[u] = false;
            // Explore the neighbors of the current node
            for (auto e : g[u]){
                int v = e.to, w = e.w;
                // Update the distance if a shorter path is found
                if (dis[v] < dis[u] + w){
                    dis[v] = dis[u] + w;
                    if (!vis[v]){
                        vis[v] = true;
                        q.push(v);
                    }
                }
            }
        }
        // Output the result
        cout << n - dis[n] << endl;
    }
    return 0;
}